package com.usian.mapper;

import com.usian.game.Game;
import com.usian.role.Role;
import com.usian.user.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GameMapper {
    @Select("select * from role ")
    List<Role> getRole();
    @Insert("insert into game(room_id,user_id,role_id) values (#{roomId},#{userId},#{roleId})")
    void insertGame(Game game);
    @Select("select * from game where room_id=#{roomid}")
    List<Game> getGame(Integer roomid);
    @Select("select * from game where room_id=#{roomid}")
    List<Game> getGameUser(Integer roomid);
//    判断女巫是否拥有解药
    @Select("select skill from game where room_id = #{roomid} and role_id = 2")
    Integer getSkill(Integer roomid);
    //    判断女巫是否拥有毒药
    @Select("select poison from game where room_id = #{roomid} and role_id = 2")
    Integer getPosion(Integer roomid);
//    假死
    @Update("update game set deal = 1 where room_id = #{roomid} and id = #{killUserId}")
    void usePoison(Integer roomid,Integer killUserId);
//    直死
    @Update("update game set deal = 1 where room_id = #{roomid} and user_id = #{killUserId}")
    void killUser(Integer roomid, Integer userId, Integer killUserId);

    @Select("select * from game where id = #{userId1}")
    List<Game> selectById(Integer userId1);

    @Select("select role_name from role where id = #{roleId}")
    String getRoleName(Integer roleId);

    @Insert("insert into game_logs(room_id, user_id, kill_user_id, role_name, cause_of_death,kill_role_name)" +
            " values (#{roomid},#{userId},#{userId1},#{roleName},#{causeOfDeath},#{killRoleName}) ")
    void addGameLogs(Integer roomid, Integer userId, Integer userId1, String roleName, String causeOfDeath, String killRoleName);
    @Update("update game set deal = 0 where room_id = #{roomId} and user_id = #{userId}")
    void updateById(Game game);
    @Select("select * from user where id = #{userId}")
    User selectByIdUser(Integer userId);
    @Update("update user set charisma = #{charisma} where id = #{id}")
    void updateByIdUser(User user);
}
